<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/3/1
 * Time: 10:37
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class About extends Base
{
    /**
     * @return mixed|\think\response\Json
     * 关于我们
     */
    public function aboutIndex(){
        if(Request::instance()->isPost()){
            $about_us = input('about_us');//内容
            $res = Db::table('up_about_us')->where('about_id', 1)->setField('about_us', $about_us);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $about_us = Db::table('up_about_us')->where('about_id', 1)->value('about_us');
        $this->assign('about_us', $about_us);
        return $this->fetch('about/aboutindex');
    }
    /**
     * @return mixed|\think\response\Json
     * 编辑用户协议
     */
    public function user(){
        if(Request::instance()->isPost()){
            $userAgreement = input('about_us');
            $res = Db::table('up_about_us')->where('about_id', 1)->update(['user_agreement' => $userAgreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_about_us')->where('about_id', 1)->value('user_agreement');
        $this->assign('about_us', $agreement);
        return $this->fetch('about/user');
    }
    /**
     * @return mixed|\think\response\Json
     * 编辑隐私协议
     */
    public function yinsi(){
        if(Request::instance()->isPost()){
            $userAgreement = input('about_us');
            $res = Db::table('up_about_us')->where('about_id', 1)->update(['user_priavcy' => $userAgreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_about_us')->where('about_id', 1)->value('user_priavcy');
        $this->assign('about_us', $agreement);
        return $this->fetch('about/yinsi');
    }
    /**
     * @return mixed|\think\response\Json
     * 编辑隐私协议
     */
    public function sendcoin(){
        if(Request::instance()->isPost()){
            $userAgreement = input('super_time');
            $res = Db::table('up_about_us')->where('about_id', 3)->update(['super_time' => $userAgreement]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_about_us')->where('about_id', 3)->value('super_time');
        $this->assign('super_time', $agreement);
        return $this->fetch('about/sendcoin');
    }
}